<?php

class login extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('connect');
        $this->load->library('session');
    }

    function checklogin() {
        if ($_POST) {
            $email = $_POST['email'];
            $pass = $_POST['password'];
            $a = $this->connect->checklogin($email, $pass);
            $b = $this->connect->getinfo($email);
            foreach ($b as $i)
            {
                $avarta = $i->avarta;
                $name = $i->name;
                $id = $i->user_id;
                $city =$i->city;
            }
          //  $c = $this->connect->countmessage($id);
            if ($a) {
                $this->session->set_userdata('email', $email); 
                $this->session->set_userdata('id', $id); 
                $this->session->set_userdata('name',$name ); 
                $this->session->set_userdata('avarta',$avarta ); 
               $this->session->set_userdata('city',$city ); 
                echo 'ok';
                
            } else {
                echo 'Email hoặc mật khẩu không đúng!';
            }
        }
    }
    
    function logout()
    {
        $this->session->sess_destroy();
       // $this->load->view('index');
        header("Location: http://localhost:8080/nfa/index.php");
    }

}

?>
